package com.xk._01基础篇._06二叉搜索树02;

import com.xk._01基础篇._06二叉搜索树02.printer.BinaryTrees;
import com.xk._01基础篇._06二叉搜索树02.tree.BST;
import com.xk._01基础篇._06二叉搜索树02.tree.BinaryTree;

/**
 * @description:
 * @author: xu
 * @date: 2022/9/20 1:29
 */
public class Main {
    public static void main(String[] args) {
        /*BST<Integer> bst0 = new BST<>();
        *//*for (int i = 0; i < 30; i++) {
            bst0.add(new Random().nextInt(100));
        }*//*
        Integer[] nums = new Integer[]{ 7,4,9,2,5,8,11,3,12,1 };
        for (int i = 0; i < nums.length; i++) {
            bst0.add(nums[i]);
        }
        BinaryTrees.println(bst0);

        bst0.remove(7);
        System.out.println("=========================================");
        BinaryTrees.println(bst0);*/



        Integer[] nums = new Integer[]{ 7,4,9,2,5,8,11,3,12,1 };

        BST<Integer> bst = new BST<>();
        for (int i = 0; i < nums.length; i++) {
            bst.add(nums[i]);
        }
        BinaryTrees.println(bst);
        System.out.println("=========================================");
        System.out.print("前序遍历：");
        bst.preOrder(new BinaryTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print(element + " ");
            }
        });
        System.out.println();
        System.out.print("中序遍历：");
        bst.inOrder(new BinaryTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print(element + " ");
            }
        });
        System.out.println();
        System.out.print("后序遍历：");
        bst.postOrder(new BinaryTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print(element + " ");
            }
        });
        System.out.println();
        System.out.print("层序遍历：");
        bst.levelOrder(new BST.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print("_" + element + "_ ");
            }
        });
        System.out.println();
        //System.out.println("===============================");


        /*BST<Person> bst1 = new BST<>();
        for (int i = 0; i < nums.length; i++) {
            bst1.add(new Person(nums[i]));
        }
        BinaryTrees.println(bst1);
        System.out.println("=========================================");

        BST<Person> bst2 = new BST<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o2.compareTo(o1);
            }
        });
        for (int i = 0; i < nums.length; i++) {
            bst2.add(new Person(nums[i]));
        }
        BinaryTrees.println(bst2);*/
    }
}
